/**
 * @author ex_chenzy59
 * @since 2025/2/27
 * 配合虚拟线程使用
 */
public class 局部作用域变量 {
    private static final ScopedValue<String> X = ScopedValue.newInstance();

    void foo() {
        ScopedValue.where(X, "hello").run(() -> {
            bar();
        });
    }

    void bar() {
        System.out.println(X.get()); // prints hello
        ScopedValue.where(X, "goodbye").run(() -> baz());
        System.out.println(X.get()); // prints hello
    }

    void baz() {
        System.out.println(X.get()); // prints goodbye
    }

    public static void main(String[] args) {
        new 局部作用域变量().foo();
    }
}
